//
//  RCTCarouselManager.m
//  ReactNativeDemo
//
//  Created by AceWei on 2017/8/20.
//  Copyright © 2017年 AceWei. All rights reserved.
//

#import "RCTCarouselManager.h"
#import "RCTCarouselView.h"
#import "ImageBrowserView.h"

#import <React/RCTEventDispatcher.h>
#import <React/RCTBridge.h>

@interface RCTCarouselManager ()<SDCycleScrollViewDelegate>

@end

@implementation RCTCarouselManager

RCT_EXPORT_MODULE()

RCT_EXPORT_VIEW_PROPERTY(imageURLStringsGroup, NSArray)
RCT_EXPORT_VIEW_PROPERTY(titlesGroup, NSArray)
RCT_EXPORT_VIEW_PROPERTY(onClickBanner, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(clickItemOperationBlock, RCTBubblingEventBlock)
// clickItemOperationBlock

RCT_EXPORT_METHOD(testNormalEvent:(NSString *)name forSomething:(NSString *)thing)
{
    NSString *info = [NSString stringWithFormat:@"Test: %@\nFor: %@", name, thing];
    
    NSLog(@"%@", info);
}


- (UIView *)view
{
//    RCTCarouselView *cycleScrollView = [RCTCarouselView cycleScrollViewWithFrame:CGRectZero imageNamesGroup:nil];
    
//    RCTCarouselView *cycleScrollView = [RCTCarouselView new];
//    cycleScrollView.delegate = self;
    
    
//    RCTCarouselView *cycleScrollView = [RCTCarouselView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:nil];
//    
//    return cycleScrollView;
    
    
    RCTCarouselView *testScrollView = [RCTCarouselView cycleScrollViewWithFrame:CGRectZero delegate:nil placeholderImage:nil];
    
    testScrollView.titleLabelBackgroundColor = [UIColor clearColor];
    testScrollView.titleLabelHeight = 20;
    testScrollView.titleLabelTextFont = [UIFont boldSystemFontOfSize:13];
    
    
    __weak RCTCarouselView *tv = testScrollView;
    testScrollView.clickItemOperationBlock = ^(NSInteger index){
        if (!tv.onClickBanner) {
            return;
        }
        
        NSDictionary *dic = @{@"target": tv.reactTag,
                              @"name": @"AceWei",
                              @"index": @(index)};
        
        tv.onClickBanner(dic);
    };
    
    return testScrollView;
}


- (void)cycleScrollView:(RCTCarouselView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if (!cycleScrollView.onClickBanner) {
        return;
    }
    
    NSDictionary *dic = @{@"target": cycleScrollView.reactTag,
                          @"name": @"AceWei",
                          @"index": @(index)};
    
    cycleScrollView.onClickBanner(dic);
}

@end
